﻿using System;
using System.ComponentModel;
using System.Text;

namespace DataConvertLib
{
	/// <summary>
	/// 字符串类型数据转换类
	/// </summary>
	// Token: 0x0200000D RID: 13
	[Description("字符串类型数据转换类")]
	public class StringLib
	{
		/// <summary>
		/// 将字节数组转换成字符串
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="start">开始索引</param>
		/// <param name="count">数量</param>
		/// <returns>转换结果</returns>
		// Token: 0x0600005E RID: 94 RVA: 0x00004764 File Offset: 0x00002964
		[Description("将字节数组转换成字符串")]
		public static string GetStringFromByteArrayByBitConvert(byte[] value, int start, int count)
		{
			return BitConverter.ToString(value, start, count);
		}

		/// <summary>
		/// 将字节数组转换成字符串
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <returns>转换结果</returns>
		// Token: 0x0600005F RID: 95 RVA: 0x00004780 File Offset: 0x00002980
		[Description("将字节数组转换成字符串")]
		public static string GetStringFromByteArrayByBitConvert(byte[] value)
		{
			return BitConverter.ToString(value, 0, value.Length);
		}

		/// <summary>
		/// 将字节数组转换成带编码格式字符串
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="start">开始索引</param>
		/// <param name="count">数量</param>
		/// <param name="encoding">编码格式</param>
		/// <returns>转换结果</returns>
		// Token: 0x06000060 RID: 96 RVA: 0x0000479C File Offset: 0x0000299C
		[Description("将字节数组转换成带编码格式字符串")]
		public static string GetStringFromByteArrayByEncoding(byte[] value, int start, int count, Encoding encoding)
		{
			return encoding.GetString(ByteArrayLib.GetByteArrayFromByteArray(value, start, count));
		}

		/// <summary>
		/// 将字节数组转换成带编码格式字符串
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="encoding">编码格式</param>
		/// <returns>转换结果</returns>
		// Token: 0x06000061 RID: 97 RVA: 0x000047BC File Offset: 0x000029BC
		[Description("将字节数组转换成带编码格式字符串")]
		public static string GetStringFromByteArrayByEncoding(byte[] value, Encoding encoding)
		{
			return encoding.GetString(ByteArrayLib.GetByteArrayFromByteArray(value, 0, value.Length));
		}

		/// <summary>
		/// 根据起始地址和长度将字节数组转换成带16进制字符串
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="start">开始索引</param>
		/// <param name="count">数量</param>
		/// <param name="segment">连接符</param>
		/// <returns>转换结果</returns>
		// Token: 0x06000062 RID: 98 RVA: 0x000047E0 File Offset: 0x000029E0
		[Description("根据起始地址和长度将字节数组转换成带16进制字符串")]
		public static string GetHexStringFromByteArray(byte[] value, int start, int count, string segment = " ")
		{
			byte[] byteArrayFromByteArray = ByteArrayLib.GetByteArrayFromByteArray(value, start, count);
			StringBuilder stringBuilder = new StringBuilder();
			foreach (byte b in byteArrayFromByteArray)
			{
				bool flag = segment.Length == 0;
				if (flag)
				{
					stringBuilder.Append(string.Format("{0:X2}", b));
				}
				else
				{
					stringBuilder.Append(string.Format("{0:X2}{1}", b, segment));
				}
			}
			bool flag2 = segment.Length != 0 && stringBuilder.Length > 1 && stringBuilder.ToString().Substring(stringBuilder.Length - segment.Length) == segment;
			if (flag2)
			{
				stringBuilder.Remove(stringBuilder.Length - segment.Length, segment.Length);
			}
			return stringBuilder.ToString();
		}

		/// <summary>
		/// 将整个字节数组转换成带16进制字符串
		/// </summary>
		/// <param name="source">字节数组</param>
		/// <param name="segment">连接符</param>
		/// <returns>转换结果</returns>
		// Token: 0x06000063 RID: 99 RVA: 0x000048BC File Offset: 0x00002ABC
		[Description("将整个字节数组转换成带16进制字符串")]
		public static string GetHexStringFromByteArray(byte[] source, string segment = " ")
		{
			return StringLib.GetHexStringFromByteArray(source, 0, source.Length, segment);
		}

		/// <summary>
		/// 将字节数组转换成西门子字符串
		/// </summary>
		/// <param name="source">字节数组</param>
		/// <param name="start">开始索引</param>
		/// <param name="length">长度</param>
		/// <param name="emptyStr">如果为空，显示什么内容</param>
		/// <returns>转换结果</returns>
		// Token: 0x06000064 RID: 100 RVA: 0x000048DC File Offset: 0x00002ADC
		[Description("将字节数组转换成西门子字符串")]
		public static string GetSiemensStringFromByteArray(byte[] source, int start, int length, string emptyStr = "empty")
		{
			byte[] byteArrayFromByteArray = ByteArrayLib.GetByteArrayFromByteArray(source, start, length + 2);
			int num = (int)byteArrayFromByteArray[1];
			bool flag = num > 0;
			string result;
			if (flag)
			{
				result = Encoding.GetEncoding("GBK").GetString(ByteArrayLib.GetByteArrayFromByteArray(byteArrayFromByteArray, 2, num));
			}
			else
			{
				result = emptyStr;
			}
			return result;
		}

		/// <summary>
		/// 根据起始地址和长度将各种类型数组转换成字符串
		/// </summary>
		/// <typeparam name="T">数据类型</typeparam>
		/// <param name="value">数组</param>
		/// <param name="start">开始索引</param>
		/// <param name="length">长度</param>
		/// <param name="segment">连接符</param>
		/// <returns>返回结果</returns>
		// Token: 0x06000065 RID: 101 RVA: 0x00004924 File Offset: 0x00002B24
		[Description("根据起始地址和长度将各种类型数组转换成字符串")]
		public static string GetStringFromValueArray<T>(T[] value, int start, int length, string segment = " ")
		{
			bool flag = start < 0;
			if (flag)
			{
				throw new ArgumentException("开始索引不能为负数");
			}
			bool flag2 = length <= 0;
			if (flag2)
			{
				throw new ArgumentException("长度必须为正数");
			}
			bool flag3 = value.Length < start + length;
			if (flag3)
			{
				throw new ArgumentException("字节数组长度不够或开始索引太大");
			}
			T[] array = new T[length];
			Array.Copy(value, start, array, 0, length);
			return StringLib.GetStringFromValueArray<T>(array, segment);
		}

		/// <summary>
		/// 各种类型数组转换成字符串
		/// </summary>
		/// <typeparam name="T">数据类型</typeparam>
		/// <param name="value">数组</param>
		/// <param name="segment">连接符</param>
		/// <returns>返回结果</returns>
		// Token: 0x06000066 RID: 102 RVA: 0x00004994 File Offset: 0x00002B94
		[Description("各种类型数组转换成字符串")]
		public static string GetStringFromValueArray<T>(T[] value, string segment = " ")
		{
			StringBuilder stringBuilder = new StringBuilder();
			bool flag = value.Length != 0;
			if (flag)
			{
				foreach (T t in value)
				{
					bool flag2 = segment.Length == 0;
					if (flag2)
					{
						stringBuilder.Append(t.ToString());
					}
					else
					{
						stringBuilder.Append(t.ToString() + segment.ToString());
					}
				}
			}
			bool flag3 = segment.Length != 0 && stringBuilder.Length > 1 && stringBuilder.ToString().Substring(stringBuilder.Length - segment.Length) == segment;
			if (flag3)
			{
				stringBuilder.Remove(stringBuilder.Length - segment.Length, segment.Length);
			}
			return stringBuilder.ToString();
		}
	}
}
